<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<%@ include file="/WEB-INF/jsp/frm/workflow/startpanel/process-start.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>旅游的流程发起页面</title>
<script src="${pageContext.request.contextPath}/resource/js/gacx/workflow/elecmanage/elec_apply.js"></script>

<!-- 电子公函申请新增 -->
<link href="${pageContext.request.contextPath}/resource/css/def/ztree/metro.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/resource/css/def/bootstrap/ace/ace-part2.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/resource/css/def/bootstrap/ace/ace.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/resource/css/def/frm/common/common.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/resource/js/jquery/plugin/handlebars-v3.0.1.js"></script>
<script src="${pageContext.request.contextPath}/resource/js/bootstrap/validator/bootstrapValidator.js"></script>
<link href="${pageContext.request.contextPath}/resource/css/index.css" rel="stylesheet">
<script src="${prcs}/js/jquery/plugin/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/jquery/plugin/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/jquery/plugin/ajaxfileupload.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/frm/sys/disOrgTree.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/layer/layer.min.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resource/css/dzgh/info_publish.css">

</head>
<script type="text/javascript">

window.onload = function(){ 
	if(null == $("#TravelForm").data('bootstrapValidator')) {
		$("#TravelForm").bootstrapValidator(checkValidator);
	}
	resetValidator();
	//查询地区列表
	//getAreaList();
	//查询类型    0：手机号、1：身份证、2：其他
	//$("#selectType").val("0");
	
	changeSelGroup();
} 

//判读下拉框
function changeSelGroup(){
	$("#saveBtn").attr("disabled", false);
}

function resetValidator(){
	if($("#TravelForm").data('bootstrapValidator')){
		$("#TravelForm").data('bootstrapValidator').resetForm(false);
	}
}

var checkValidator = {
		message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
    	submitHandler: function(validator, form, submitButton) {
    		 
    		   showStartPanel();
    		   //$("#saveBtn").removeAttr("disabled");
    		   $("#saveBtn").attr("disabled",false);
    	},
        fields: {
        	projName:{
				validators: {
					 notEmpty :{message: '<font color="red">请输入'+'项目名称</font>'}
				}	
			},
			projContent:{
				validators: {
					 notEmpty :{message: '<font color="red">请输入'+'项目内容</font>'}
				}	
			},
			myfile:{
				validators: {
					 notEmpty :{message: '<font color="red">请上传'+'附件</font>'}
				}	
			},
			
        }
}


	function uploadAttachmentAj(){
		var myfile = $("#myfile").val();
		var id = document.getElementById("projId").value;
		if (myfile == "") {
			layer.alert("请选择需要上传的文件");
		} else {
			var dom = document.getElementById("myfile");
			var fSize;
			if (dom.files)
				fSize = dom.files[0].size;
			else
				fSize = 10;
			
			var MB = (100 * 1024 * 1024).toString();
			if (fSize > MB) {
				layer.alert("上传文件大小超出限制,请上传小于100M的文件");
			} else {
				$.ajaxFileUpload({
							url : "../projApplyController/uploadAttachment.action",
							type : "post",
							data : {
								projId : id
							},
							fileElementId : "myfile",
							dataType : "text/html",
							success : function(data) {
								var dataObj = eval('(' + data + ')');
								// 获取上传文件的原文件名
								layer.alert(dataObj.msg);
								var oldname = dataObj.oldname;
								var size = dataObj.size;
								var newname = "newname";
								$("#fileName").val(oldname);
								//alert(oldname);
								var msg = dataObj.msg;
								// 在ul列表中展示原文件名
								var attaContent = "<li id='conttt' style='width:440px;padding-top:12px;' class='list-group-item' filename='" 
			          + newname 
			          + "'><div style= ' cursor:pointer; float:left; width:275px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; margin: 0 ' title='"+oldname+"'>"
										+ oldname 
										+ "</div>"
										+ "&nbsp;<a op='del' style='height:30px;width:80px;float: right;cursor:pointer;margin-right:-20px;' filename='" 
			          + newname 
			          + "'><img src='${pageContext.request.contextPath}/resource/images/trash.png' style='margin-top:-4px;'> 删除</a></li>";
							
								$("#files").append(attaContent);
								// 提交form表单时将 封装有上传文件名的 attachment 添加到隐藏域中 
								$("#myfile").attr("disabled", true);
								$("#upload").attr("disabled", true);
								$("#saveBtn").attr("disabled", false);
								delFile();
							}
						});
			}
		}
	}
	
	
	function delFile() {
		  $("a[op]").unbind();
		  $("a[op]").click(function() {
			var id = document.getElementById("projId").value;
			var oldFileName = $("#fileName").val();
			//alert("id="+id);
		    var deldeldel = $(this);
		    if (confirm("确认要删除该附件吗?")) {
		      $.ajax({
		        url: "../projApplyController/delAttachment.action",
		        //data: "projId=" + id,"oldFileName="+
		        data:{projId:id,oldFileName:oldFileName},
		        dataType: "json",
		        type: "post",
		        success: function(data) {
		          if (data) {
		            deldeldel.parent().remove();
		            $(this).parent().remove();
		            
		            $("#myfile").attr("disabled", false);
		            $("#upload").attr("disabled", false);
		            $("#fileName").val("");
		            alert("删除成功");
		          } else {
		            alert("删除失败");
		          }
		        }
		      });
		    }
		  });
		}
</script>
<body>

	
	<div style="height: 100%;" class="main-content">
		<div class="page-content" style="background: #fff">
			<form class="form-horizontal" role="form" id="TravelForm"
				autocomplete="off" enctype="multipart/form-data">
				<input type="hidden" id="processDefinitionKey"
					name="processDefinitionKey" value="GaWorkflow" /> <input
					type="hidden" id="assigneeDz" name="assigneeDz" /> <input
					type="hidden" id="taskDefinitionKey" name="taskDefinitionKey" />
				<div class="head-title">
					<span>旅游项目申请</span>
				</div>
				<div class="check-div">
					<div class="row check-row apply-row">
						<div class="col-sm-6">
							<div class="input-group">
								<span class="input-group-addon">项目编码</span> <input type="text"
									id="projId" name="projId" value="${projId}" readonly="readonly" class="form-control"
									placeholder="请输入项目编码" />
							</div>
						</div>
						
						<div class="col-sm-6">
							<div class="input-group">
								<span class="input-group-addon">项目名称</span> <input type="text"
								 id="projName"	class="form-control" name="projName" placeholder="请输入项目名称">
							</div>
						</div>
					</div>
			


					<div class="row apply-row" style="height: 52px;">
						<div class="col-sm-12">
							<div class="input-group">
								<span class="input-group-addon">项目内容</span>
								<textarea id="projContent" class="form-control" name="projContent"
									placeholder="必填，字符串"></textarea>
							</div>
						</div>
					</div>

					<div class="row apply-row" style="height: 52px;">
						<div class="col-sm-12">
							<div class="input-group">
								<span class="input-group-addon">备注</span>
								<textarea id="remark" class="form-control"
									name="remark" placeholder="非必填"></textarea>
							</div>
						</div>
					</div>

					<div class="row apply-row">
						<div class="col-sm-12">
							<div class="input-group">
								<span class="input-group-addon">附件</span>
								<div class="form-control"
									style="position: static; float: none; clear: both;">
									<div>

										<div id="wj2">
											<div style="padding-top: 5px;">

												<div class="input-append">
													<input type="file" name="myfile" id="myfile"
														style="height: 30px; width: 250px; display: inline" />

													<button id="upload" onclick="uploadAttachmentAj()"
														type="button" class="btn btn-info"
														style="height: 30px; width: 100px; display: inline">上传</button>

												</div>
												<div style="margin-top: 15px;">
													<input type="hidden" id="fileName" />
													<ul id="files" class="updata_fibox"></ul>
												</div>
												<div></div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>

					<div class="row apply-row">
						<div class="modal-footer">
							<button type="submit" id="saveBtn" class="btn btn-info">发&nbsp;&nbsp;起</button>
							<!-- <button id="showPanel" type="button" class="btn btn-success" onclick="showStartPanel();">发起</button>  -->
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>